<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>忘记密码</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=yes" name="format-detection" />
    <link href="<%=basepath%>css/index.css" rel="stylesheet" type="text/css">
    <link href="<%=basepath%>css/registered.css" rel="stylesheet" type="text/css">
    <script src="<%=basepath%>js/jquery-1.8.3.min.js"></script>
    <script src="<%=basepath%>js/layer/layer.js"></script>
    <script src="<%=basepath%>js/jquery.md5.js"></script>
</head>
<body>
<div class="viewport">
    <div class="header">
        <div class="header-1">
            <a href="javascrpt:void(0)" class="header-2">
                <span id="account" class="account">${empty user.realName ? '' : user.realName}</span>&nbsp;&nbsp;<span id="deptName" class="deptName">${user.departmentName}</span>
            </a>
            <a href="javascript:history.go(-1)" class="back">返回</a>
            <span class="span-num">WWP11120</span>
        </div>
    </div>
        <div class="content m-top">
            <form method="post" id="myform" action="/wape-web/api/core/centerService">
            <div class="content-2"><input type="text" placeholder="请输入手机号码" id="registerNum" maxlength="15px;" name="registerNum"></div>
            <div class="content2-2"><input type="text" placeholder="请输入短信验证码" maxlength="6px" id="sms" name="code" class="content2-2-1"><input type="button" value="获取短信验证码" id="btn" class="btn"> </div>
            <div class="content2-3"><input type="password" placeholder="设置密码" maxlength="25px" id="password" name="pwd"></div>
            <div class="content2-3"><input type="password" placeholder="确认密码" maxlength="25px" id="again"></div>
            <div class="content-f"></div>
            <div class="content-7"><input type="submit" value="确认申请" class="submit"></div>
            <input type="hidden" name="serviceCode" value="5004U02" />
            </form>
        </div>
</div>
</body>
</html>
<script type="text/javascript">
    /*错误提示*/
    $(function(){
        var error = "${requestScope.returnMsg}";
        if(error != "" && error != "成功!"){
            layer.msg(error,{shadeClose:true,shade:0.1,time:2000});
        }
    });
    /*获取验证码时间*/
    $(function(){
    	var wait=60;
        function time(o) {
            if (wait == 0) {
            	$("#btn").removeClass("gray");
                o.removeAttribute("disabled");
                o.value="免费获取验证码";
                wait = 60;
            } else {
            	$("#btn").addClass("gray");
                o.setAttribute("disabled", true);
                o.value="重新发送(" + wait + ")";
                wait--;
                setTimeout(function() {
                            time(o)
                        },
                        1000);
            }
        }
        $("#btn").click(function(){
        	var registerNum=$("#registerNum").val();
        	var patrn =/^1[3,5,7,8]\d{9}$/;
        	if(registerNum == "" || !patrn.test(registerNum)){
        		layer.msg("请输入正确的手机号",{shadeClose:true,shade:0.1,time:2000});
        	}
        	else{
        		time(this);
            	/*ajax*/
            	var registerNum=$("#registerNum").val();
            	$.ajax({
            		type:"post",
            		url:"/wape-web/api/core/centerService",
            		data:{
                        serviceCode:"1001W05",
                        registerNum:registerNum
                    },
                    success:function(data){
                    	var smsCode = eval("("+data+")");
                    	if(smsCode.returnCode == "200"){
                    		layer.msg("发送成功!",{shadeClose:true,shade:0.1,time:2000});
                    	}
                    	else{
                    		layer.msg("发送失败，请重新发送",{shadeClose:true,shade:0.1,time:2000});
                    	}
                    }
            	});
        	}
        });
    }); 
    /*  */
    $(function(){
        $("#myform").submit(function(){
            var registerNum=$("#registerNum").val();
            var patrn =/^1[3,5,7,8]\d{9}$/;
            var sms=$("#sms").val();
            var password=$("#password").val();
            var again=$("#again").val();
            if(registerNum == ""){
            	layer.msg("请输入手机号",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(!patrn.test(registerNum)){
                layer.msg("请输入正确格式手机号",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(sms==""){
            	layer.msg("请输入短信验证码",{shadeClose:true,shade:0.1,time:2000});
                return false;
             }
            else if(password==""){
                layer.msg("请输入密码",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(password.length<6){
                layer.msg("密码不能少于6个字符",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(password.length>20){
                layer.msg("密码不能大于20个字符",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(again==""){
                layer.msg("请再次输入密码",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(password!=again){
                layer.msg("两次密码不一致",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else{
                var b = $("#password").val();
                var c = $.md5($.md5($.md5(b)));
                $("#password").val(c);
                layer.load();
                setTimeout(function(){
              	  layer.closeAll();
              	  layer.msg("网络异常，请重新尝试！",{shadeClose:true,shade:0.1,time:2000});
              	}, 30000);
            }
        })
    });
</script>

